from scapy.all import *
import sys

class ARPClient:
	
	def resolveHardwareAddress(self, ipAddress, interface):
		
		arpPacket = self.__buildARPPacket(ipAddress)
		res = sr(arpPacket, iface = interface)
		answeredPackets = res[0]
		return answeredPackets.summary() 


	#Metodo privado que crea un paquete ARP bradcast con direccion origen ipAdress
	def __buildARPPacket(self, ipAddress):		
		arpPacket = ARP()
		arpPacket.pdst = ipAddress
		arpPacket.hwdst = "ff:ff:ff:ff:ff:ff"			 
		return arpPacket		

		
	def sniff(self, limitTime, interface):
		res = sniff(filter = "arp", timeout = limitTime, iface = interface, prn = self.customPacketDisplay)


	def customPacketDisplay(self, p):
		if ARP in p:
			print p[ARP].psrc + " -> " + p[ARP].pdst
		
